home *** CD-ROM | disk | FTP | other *** search
/ isnet Internet / Isnet Internet CD.iso / prog / hiz / 09 / 09.exe / adynware.exe / perl / lib / ExtUtils / Command.pm next >
Encoding:
Perl POD Document  |  1999-12-28  |  3.6 KB  |  208 lines

  1. package ExtUtils::Command;
  2. use strict;
  3. use Carp;
  4. use File::Copy;
  5. use File::Compare;
  6. use File::Basename;
  7. use File::Path qw(rmtree);
  8. require Exporter;
  9. use vars qw(@ISA @EXPORT $VERSION);
  10. @ISA     = qw(Exporter);
  11. @EXPORT  = qw(cp rm_f rm_rf mv cat eqtime mkpath touch test_f);
  12. $VERSION = '1.01';
  13.  
  14. =head1 NAME
  15.  
  16. ExtUtils::Command - utilities to replace common UNIX commands in Makefiles etc.
  17.  
  18. =head1 SYNOPSIS
  19.  
  20.   perl -MExtUtils::Command -e cat files... > destination
  21.   perl -MExtUtils::Command -e mv source... destination
  22.   perl -MExtUtils::Command -e cp source... destination
  23.   perl -MExtUtils::Command -e touch files...
  24.   perl -MExtUtils::Command -e rm_f file...
  25.   perl -MExtUtils::Command -e rm_rf directories...
  26.   perl -MExtUtils::Command -e mkpath directories...
  27.   perl -MExtUtils::Command -e eqtime source destination
  28.   perl -MExtUtils::Command -e chmod mode files...
  29.   perl -MExtUtils::Command -e test_f file
  30.  
  31. =head1 DESCRIPTION
  32.  
  33. The module is used in Win32 port to replace common UNIX commands.
  34. Most commands are wrapers on generic modules File::Path and File::Basename.
  35.  
  36. =over 4
  37.  
  38. =cut
  39.  
  40. sub expand_wildcards
  41. {
  42.  @ARGV = map(/[\*\?]/ ? glob($_) : $_,@ARGV);
  43. }
  44.  
  45. =item cat 
  46.  
  47. Concatenates all files mentioned on command line to STDOUT.
  48.  
  49. =cut 
  50.  
  51. sub cat ()
  52. {
  53.  expand_wildcards();
  54.  print while (<>);
  55. }
  56.  
  57. =item eqtime src dst
  58.  
  59. Sets modified time of dst to that of src
  60.  
  61. =cut 
  62.  
  63. sub eqtime
  64. {
  65.  my ($src,$dst) = @ARGV;
  66.  open(F,">$dst");
  67.  close(F);
  68.  utime((stat($src))[8,9],$dst);
  69. }
  70.  
  71. =item rm_f files....
  72.  
  73. Removes directories - recursively (even if readonly)
  74.  
  75. =cut 
  76.  
  77. sub rm_rf
  78. {
  79.  rmtree([grep -e $_,expand_wildcards()],0,0);
  80. }
  81.  
  82. =item rm_f files....
  83.  
  84. Removes files (even if readonly)
  85.  
  86. =cut 
  87.  
  88. sub rm_f
  89. {
  90.  foreach (expand_wildcards())
  91.   {
  92.    next unless -f $_;        
  93.    next if unlink($_);
  94.    chmod(0777,$_);           
  95.    next if unlink($_);
  96.    carp "Cannot delete $_:$!";
  97.   }
  98. }
  99.  
  100. =item touch files ...
  101.  
  102. Makes files exist, with current timestamp 
  103.  
  104. =cut 
  105.  
  106. sub touch
  107. {
  108.  expand_wildcards();
  109.  while (@ARGV)
  110.   {
  111.    my $file = shift(@ARGV);               
  112.    open(FILE,">>$file") || die "Cannot write $file:$!";
  113.    close(FILE);
  114.   }
  115. }
  116.  
  117. =item mv source... destination
  118.  
  119. Moves source to destination.
  120. Multiple sources are allowed if destination is an existing directory.
  121.  
  122. =cut 
  123.  
  124. sub mv
  125. {
  126.  my $dst = pop(@ARGV);
  127.  expand_wildcards();
  128.  croak("Too many arguments") if (@ARGV > 1 && ! -d $dst);
  129.  while (@ARGV)
  130.   {
  131.    my $src = shift(@ARGV);               
  132.    move($src,$dst);
  133.   }
  134. }
  135.  
  136. =item cp source... destination
  137.  
  138. Copies source to destination.
  139. Multiple sources are allowed if destination is an existing directory.
  140.  
  141. =cut 
  142.  
  143. sub cp
  144. {
  145.  my $dst = pop(@ARGV);
  146.  expand_wildcards();
  147.  croak("Too many arguments") if (@ARGV > 1 && ! -d $dst);
  148.  while (@ARGV)
  149.   {
  150.    my $src = shift(@ARGV);               
  151.    copy($src,$dst);
  152.   }
  153. }
  154.  
  155. =item chmod mode files...
  156.  
  157. Sets UNIX like permissions 'mode' on all the files.
  158.  
  159. =cut 
  160.  
  161. sub chmod
  162. {
  163.  my $mode = shift(@ARGV);
  164.  chmod($mode,expand_wildcards()) || die "Cannot chmod ".join(' ',$mode,@ARGV).":$!";
  165. }
  166.  
  167. =item mkpath directory...
  168.  
  169. Creates directory, including any parent directories.
  170.  
  171. =cut 
  172.  
  173. sub mkpath
  174. {
  175.  File::Path::mkpath([expand_wildcards()],1,0777);
  176. }
  177.  
  178. =item test_f file
  179.  
  180. Tests if a file exists
  181.  
  182. =cut 
  183.  
  184. sub test_f
  185. {
  186.  exit !-f shift(@ARGV);
  187. }
  188.  
  189. 1;
  190. __END__ 
  191.  
  192. =back
  193.  
  194. =head1 BUGS
  195.  
  196. Should probably be Auto/Self loaded.
  197.  
  198. =head1 SEE ALSO 
  199.  
  200. ExtUtils::MakeMaker, ExtUtils::MM_Unix, ExtUtils::MM_Win32
  201.  
  202. =head1 AUTHOR
  203.  
  204. Nick Ing-Simmons <F<nick@ni-s.u-net.com>>.
  205.  
  206. =cut
  207.  
  208.